@extends('layouts.master3')
@section('title')
{{"千里码-邀请"}}
@stop

@section('css')
<link href="http://www.qlcoder.com//css/bootstrap.min.css" rel="stylesheet">
<link href="http://www.qlcoder.com//css/bootstrap-theme.css" rel="stylesheet">
<link href="http://www.qlcoder.com//css/base.css" rel="stylesheet">
<link rel="stylesheet" href="/font/iconfont.css">
<link rel="stylesheet" href="/css/nprogress.css">

<link href="/css/invitation.css" rel="stylesheet">
@stop

@section('content')
    <div class="contain">
        <section class="invite_warp">
            <div class="invite_header">
                <h1>我收到的邀请</h1>
            </div>
            <div class="invite_content">
                <div class="invite_info">
                    <div class="row">
                        <div class="col-md-1 title">邀请时间</div>
                        <div class="col-md-2 title">来自</div>
                        <div class="col-md-2 title">邀请人</div>
                        <div class="col-md-2 title">所在公司</div>
                        <div class="col-md-2 title">受邀职位</div>
                        <div class="col-md-2 title">薪资待遇</div>
                        <div class="col-md-1 title"></div>
                    </div>
                </div>

                <div class="invite_list">
                    <?php foreach($data as $da){
						$aa = '<span class="acceped">已接受</span>'; 
						if(!$da["accepted"]) $aa = '<a class="acc" href="javascript:;" data-invite-id="'.$da["jobid"].'">接受邀请</a>';
                        echo '
                    <div class="invite_list_info">
                        <div class="row">
                            <div class="col-md-1 time para">'.$da["updated_at"].'</div>
                            <div class="col-md-2 from para">'.$da["title"].'</div>
                            <div class="col-md-2 detail para">
                                <span class="invite_name">'.$da["realname"].'</span>
                                <span class="depart">'.$da["department"].'</span>
                            </div>
                            <div class="col-md-2 company para">
                                <a tabindex="0" href="javascript:;" role="button"
                                   data-toggle="popover" data-placement="right"
                                   data-trigger="hover"  data-content="'.$da["slogan"].'">'.$da["company"].'</a></div>
                            <div class="col-md-2 position para">'.$da["job"].'</div>
                            <div class="col-md-2 salary para">'.$da["salary"].'</div>
                            <div class="col-md-1 accept ">'
							.$aa.'<a class="inbox" href="javascript:;" data-name="'.$da["realname"].'" data-job-id="'.$da["jobid"].'" data-id="'.$da["userid"].'" data-toggle="modal" data-target="#myModal" title="给他/她回复">私信</a>
                            </div>
                        </div>
                    </div>';
                     }?>

                </div>
            </div>
        </section>
        <!-- 弹窗-->
        <div class="invite_modal none">
            <header>接受邀请 <a href="javascript:;" class="invite_close fr"><i class="iconfont icon-close"></i></a></header>
            <section>
                <div class="title">请选择你要发送的简历方式</div>
                <div class="profile">
                    <form action="/invitation/save_attachment">
						<input type="hidden" name="_token" value="{{csrf_token()}}">
                        <div class="online ch">
                            <label><input type="radio" data-type="online"  name="profile" checked />在线简历</label>
                            <!-- if  无填写简历⬇️-->
                            <?php
                                if($flag==0) {
                                    echo '<span class="un">暂无在线简历</span>
                                    <a href="/resume" class=" fr">请填写简历</a>';
                                }
                                else if($flag>0 && $flag<3) echo '<span class="un">未完善简历</span> <div class="fr"> <a href="/resume/preview">预览</a>/<a href="/resume">修改</a></div>';
								else echo '<i class="iconfont icon-jihuo"> </i><div class="fr"> <a href="/resume/preview">预览</a>/<a href="/resume">修改</a></div>';
                            ?>
                        </div>
                        <div class="annex ch">
                            <label><input type="radio" data-type="attachment"  name="profile"/>附件简历</label>
                            <!-- if  无附件简历⬇️-->
							<?php
								if(!$flag2) echo '<span class="un pro">暂无附件简历</span>';
								else echo '<div class="res pro"><a href="'.$resume->attachment_path.'">'.$resume->attachment_name.'</a><i class="iconfont icon-jihuo"> </i></div>';
							?>
                            	<a href="javascript:;" class="upload_profile fr"><input type="file" class="complete fr" name="attachment" id="attachment" />上传附件简历</a>
                        </div>
                        <button class="send btn btn-primary">确认接受邀请</button>
						<div class="wraning"></div>
                    </form>

                </div>
            </section>
		</div>
        <!-- 遮罩-->
        <div class="task-shadow none"></div>
        <!-- 发私信弹窗  -->
        <div class="ql_letter_modal modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">发送私信</h4>
                    </div>
                    <div class="modal-body">
                        <dl>
                            <dt class="send_label">
                                <label>发给:</label>
                            </dt>
                            <dd>
                                <div class="send_name"><input type="text" readonly="true" value=""></div>
                            </dd>
                            <dt class="send_label">
                                <label>内容:</label>
                            </dt>
                            <dd class="ml">
                                <div class="send_editor">
                                    <textarea class="editor_content" style="font-weight: normal; height: 22px;"></textarea>
                                </div>
                            </dd>
                        </dl>
                    </div>
                    <div class="modal-footer">
                        <a href="javascript:;" class="close_btn" data-dismiss="modal">取消</a>
                        <button type="button" class="btn btn-primary" id="sendTo">发送</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="alert alert-warning alert-dismissible none in" role="alert"
             style="position: fixed;top: 50%;left: 50%;width: 400px;text-align: center;margin-left: -200px;margin-top: -26px;">

            <strong>你已接受邀请，技术主管会在1个工作日内给你回复!</strong>
        </div>

    </div>
@section('js')
<script src="/js/jquery.ui.widget.js"></script>
<script src="/js/jquery.fileupload.js"></script>
<script src="/js/jquery.iframe-transport.js"></script>
<script src="/js/nprogress.js"></script>
<script>
    $(function(){
        $(".company a").popover();
        // set annex first else
        $(".accept .acc").click(function(){
			$(".task-shadow,.invite_modal").removeClass("none");
			$(".profile button.send").attr("data-id",$(this).attr("data-invite-id"));
        })

        //close modal
        $(".invite_close").click(function(){
            $(".task-shadow,.invite_modal").addClass("none")
        })

        $(".inbox").click(function () {
            $(".send_name input").val($(this).attr("data-name"));
            $("#sendTo").attr("data-id",$(this).attr("data-id")).attr("data-job-id",$(this).attr("data-job-id"));
            $("textarea.editor_content").focus();
        })
        $("#sendTo").bind("click",function(){
            var sendID=$(this).attr("data-id");
			var jobID =$(this).attr("data-job-id");
            var sendContent=$("textarea.editor_content").val();
            if(sendContent!=""){
                $.get("http://www.qlcoder.com/api/user/sendmsg",{userid:sendID,content:sendContent},function(data){
                    if(data.success==true)
					{
						$.ajax({
							url:"/invitation/save_touch",
							type:"post",
							dataType:"json",
							data:{
								"_token":$("input[name='_token']").val(),
								jobid	:jobID
							},
							success:function(data){
								$("textarea.editor_content").val("");
								$('#myModal').modal('hide');
								$(".alert").removeClass("none").find("strong").html("发送成功！");
								setTimeout(function(){$(".alert.in").addClass("none")},3000);

							}
						})
                                           }
				})

            }
            else{
                return !1;
            }

		})
		$(".complete").fileupload({
                    url: '/invitation/save_attachment',
					acceptFileTypes: /(\.|\/)(pdf|doc?x|html)$/i,
					maxFileSize: 8000000,
					autoUpload:false
		}).on("fileuploadadd",function(e,data){
		//	console.log(data);
			var file = data.files[0];
			if(file.size<8000000){
				if(file.type == "application/pdf" || file.type == "text/html" || file.type == "application/msword" || file.type=="application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
					data.submit();
				}else{
					$(".wraning").html("请上传pdf,doc,docx,html格式文件！");
				}
		
			}else{
				$(".wraning").html("文件大小超过8M限制");
			}
		}).bind("fileuploadprogress", function (e, data) {
                    $(".profile button.send").attr("disabled","disabled");
                    NProgress.inc();
                }).bind("fileuploadprocessalways",function(e,data){
					var file = data.files[0];
					if(file.error){
						$(".wraning").html(file.error);
					}
				}).bind("fileuploaddone", function (e, data) {
                    NProgress.done();
                    if(data.result.suc){
                        $(".pro").html("<a href='"+data.result.path+"'>"+data.result.name+"</a><i class='iconfont icon-jihuo'></i>");
                        $(".profile button.send").removeAttr("disabled");
                        $(".wraning").html("");
                    }else{
                        $(".wraning").html(data.result.data);
                        $(".profile button.send").removeAttr("disabled");
                    }
                })	
		$(".profile button.send").click(function(e){
			e.preventDefault();
			var type = $("input[name='profile']:checked").attr("data-type"),
				id   = $(this).attr("data-id"),
				check= $("input[name='profile']:checked"),
				len  = check.parents(".ch").find("i").length;
			console.log(len);
			if(len>0){
				$.ajax({
					url:"/invitation/save_invitation",
					type:"post",
					dataType:"json",
					data:{	
						_token:$("input[name='_token']").val(),
						jobid:id,
						acc_type:type
					},
					success:function(data){
						console.log(data);
						$(".task-shadow,.invite_modal").addClass("none");	
						$(".alert.in").removeClass("none").find("strong").html("你已接受邀请，技术主管会在1个工作日内给你回复!");
						$(".warning").html("");
						$(".acc[data-invite-id='"+id+"']").replaceWith("<span class='acceped'>已接受</span>")
						setTimeout(function(){$(".alert.in").addClass("none")},3000)	
					}			
				})
			}else{
				if(check.attr("data-type")!=="online"){
					$(".wraning").html("请先上传简历");
				}else{
					$(".wraning").html("请先完善您的个人简历");
				}
				return !1;
			}	

		});
    })
</script>
@endsection
@endsection
